$().ready(function() {
    validateRule();
    layui.use(['form','table'], function() {
        var form = layui.form, table = layui.table;
    });
    $(".grid-column-qrcode").each(function() {
        $(this).click(function() {
            previewImg($(this));
        })
    });
});

$.validator.setDefaults({
    submitHandler : function() {
        update();
    }
});

function update() {
	var url = ctx +"module/device/welding/record/" + ($('#signupForm').find("#id").val() == '' ? "save" : "update");
    $.ajax({
        cache : true,
        type : "POST",
        url : url,
        data : $('#signupForm').serialize(),// 你的formid
        async : false,
        error : function(request) {
            parent.layer.alert("Connection error");
        },
        success : function(data) {
            if (data.code == 0) {
                parent.layer.msg("操作成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);

            } else {
                parent.layer.alert(data.msg)
            }
        }
    });

}
function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm").validate({
        rules : {
            sort : {
                required : true
            }
        },
        messages : {
            sort : {
                required : icon + "请输入索引"
            }
        }
    })
}
function previewImg(obj) {
    var img = new Image();
    img.src = $(obj).attr("src");
    var imgHtml = "<img src='" + img.src + "' width='100%' height='100%' style='object-fit:contain' />";
    //弹出层
    layer.open({
        type: 1,
        // shade: true,
        shadeClose : true, // 点击遮罩关闭层
        area:['80%','80%'],
        title: false, //不显示标题
        content: imgHtml, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
        cancel: function () {

        }
    });
}